package com.ydd.controller.admin;

import com.ydd.dto.YddAdvimgDTO;
import com.ydd.dto.YddAdvimgPageDTO;
import com.ydd.entity.YddAdvimg;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.IYddAdvimgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ydd_advimg")
@Api(tags = "广告图管理接口")
@Slf4j
public class AdvImgController {

    @Autowired
    private IYddAdvimgService yddAdvimgService;

    @GetMapping("/list")
    @ApiOperation("广告图分页查询")
    public Result<PageResult> pageQuery(YddAdvimgPageDTO yddAdvimgPageDTO){
        log.info("广告图分页管理",yddAdvimgPageDTO);
        PageResult pageResult = yddAdvimgService.pageQuery(yddAdvimgPageDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/del")
    @ApiOperation("删除广告图")
    public Result deleteById(Integer id){
        log.info("删除广告图{}",id);
        Boolean flag = yddAdvimgService.deleteById(id);
        if(flag){
            return Result.success();
        }else {
            return Result.error("系统默认数据，不允许删除");
        }
    }

    @GetMapping("/rowInfo")
    @ApiOperation("广告图详情")
    public Result selectById(Integer id){
        log.info("广告图详情",id);
        YddAdvimg yddAdvimg = yddAdvimgService.selectById(id);
        return Result.success(yddAdvimg);
    }

    @PostMapping("/update")
    @ApiOperation("修改广告图")
    public Result update(@RequestBody YddAdvimg yddAdvimg){
        log.info("广告图修改",yddAdvimg);
        yddAdvimgService.update(yddAdvimg);
        return Result.success();
    }

    @PostMapping("/add")
    @ApiOperation("广告图增加")
    public Result add(@RequestBody YddAdvimgDTO yddAdvimgDTO){
        log.info("广告图添加",yddAdvimgDTO);
        yddAdvimgService.add(yddAdvimgDTO);
        return Result.success();
    }
}

